package com.bagua.sbbcshop.vo;


import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

/**统一返回处理
 * @author xhou
 */
@ApiModel(value = "BasicResponse", description = "通用返回")
public class BasicResponse<T> {
    /**
     * 表示成功
     */
    public static final byte SUCCESS = 1;
    /**
     * 表示失败
     */
    public static final byte FAILURE = 0;

    @ApiModelProperty(value = "状态,0失败,1成功", dataType="byte")
    private byte state;
    @ApiModelProperty(value = "提示消息", dataType="byte")
    private String msg;

    @ApiModelProperty(value = "返回数据", dataType="byte")
    private T data;

       public BasicResponse(byte state, String msg, T data) {
        this.state = state;
        this.msg = msg;
        this.data = data;
    }

    public static <T> BasicResponse<T> success() {
        return new BasicResponse<>(SUCCESS, "", null);
    }

    public static <T> BasicResponse<T> failure() {
        return new BasicResponse<>(FAILURE, "", null);
    }

    public static <T> BasicResponse<T> success(String msg) {
        return new BasicResponse<>(SUCCESS, msg, null);
    }

    public static <T> BasicResponse<T> failure(String msg) {
        return new BasicResponse<>(FAILURE, msg, null);
    }

    public static <T> BasicResponse<T> success(String msg, T data) {
        return new BasicResponse<>(SUCCESS, msg, data);
    }

    public static <T> BasicResponse<T> failure(String msg, T data) {
        return new BasicResponse<>(FAILURE, msg, data);
    }

    public BasicResponse msg(String msg) {
        this.msg = msg;
        return this;
    }

    public BasicResponse data(T data) {
        this.data = data;
        return this;
    }
    public byte getState() {
        return state;
    }

    public void setState(byte state) {
        this.state = state;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

}
